import collections
        
class LRUCache:

    def __init__(self, capacity: int):
        self.d = collections.OrderedDict()
        self.maxlen = capacity

    def get(self, key: int) -> int:
        v = self.d.get(key, -1)
        if key in self.d:
            self.d.move_to_end(key,last=True)
        return v

    def put(self, key: int, value: int) -> None:
        self.d[key] = value
        self.d.move_to_end(key,last=True)
        if self.d.__len__() > self.maxlen:
            self.d.popitem(last=False)




# Your LRUCache object will be instantiated and called as such:
# obj = LRUCache(capacity)
# param_1 = obj.get(key)
# obj.put(key,value)
if __name__ == "__main__":
    cache = LRUCache(2)
    cache.put(1, 1)
    cache.put(2, 2)
    res = cache.get(2)
    print(res)
    res = cache.get(3)
    print(res)
    cache.put(3, 3)
    res = cache.get(1)
    print(res)